package com.lovemanai.service;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.AsyncContext;
import javax.servlet.ServletRequest;

/**
 * 异步处理类
 * @author lovemanai
 *
 */
public class Executor implements Runnable{

	//AsyncContext对象用于异步请求到指定页面
	private AsyncContext actx = null;
	
	public Executor(AsyncContext actx) {
		this.actx = actx;
	}
	
	@Override
	public void run() {
	
		try {
			Thread.sleep(1000 * 5);
			//获取ServletRequest对象
			ServletRequest request = actx.getRequest();
			List<String> books = new ArrayList<String>();
			books.add("Java编程思想");
			books.add("Java核心技术");
			books.add("深入理解计算机系统");
			request.setAttribute("books", books);
			actx.dispatch("/async1.jsp");//请求转发
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
